#
#  e_glue_ui.py
#  e-glue-pyobjc
#
#  Created by Leonardo Dinnouti on 23/10/09.
#  Copyright (c) 2009 Home. All rights reserved.
#

from Foundation import *
from AppKit import *
#from Cocoa import *
#from Quartz import *
#from LaunchServices import *
import objc

class eGlueUi(NSObject):
    leftFile = objc.IBOutlet()
    rightFile = objc.IBOutlet()
    finalImageView = objc.IBOutlet()
    leftImageView = objc.IBOutlet()
    rightImageView = objc.IBOutlet()
    cv = cvprocess.alloc().init()

    @objc.IBAction
    def rightImage_(self, sender):
        openPanel = NSOpenPanel.openPanel() 
        openPanel.runModal()
        self.rightFile.setStringValue_(openPanel.filename()) 
        self.cv.setRightImage_(self.rightFile.stringValue())
        self.rightImageView.setImageWithURL_(NSURL.fileURLWithPath_(openPanel.filename()))
        dictionary = self.rightImageView.imageProperties()
        for key in dictionary.allKeys():
            NSLog(u"key: %s, value: %s" % (key, dictionary.objectForKey_(key)))

    @objc.IBAction
    def leftImage_(self, sender):
        openPanel = NSOpenPanel.openPanel()
        openPanel.runModal()
        self.leftFile.setStringValue_(openPanel.filename())
        self.cv.setLeftImage_(self.leftFile.stringValue())
        self.leftImageView.setImageWithURL_(NSURL.fileURLWithPath_(openPanel.filename()))
#        self.cv.saveImage_imagePath_(self.leftImageView.image(), u"./" + openPanel.filename())
        self.cv.saveImage_imagePath_(self.leftImageView.image(), u"tmpleft.jpg")
#        myImageDest = CGImageDestinationCreateWithURL(u"left.jpg", kUTTypeJPEG, 1, null)
#        CGImageDestinationAddImage(myImageDest, self.leftImageView.image(), null)
#        CGImageDestinationFinalize(myImageDest)

    @objc.IBAction
    def glue_(self, sender):
        NSLog(u"Left File: " + self.leftFile.stringValue())
        NSLog(u"Right File: " + self.rightFile.stringValue())
        self.cv.glueImages_(u"newimg.png")
        urlFile = NSURL.fileURLWithPath_(u"newimg.png")
        self.finalImageView.setImageWithURL_(urlFile)
        self.cv.hello()
